package com.rykj.energy.basic.rest;

import com.rykj.energy.common.utils.Result;
import com.rykj.energy.common.utils.StringUtils;
import com.rykj.energy.database.pojo.BasicNotice;
import com.rykj.energy.database.service.INoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "通知方式")
@Slf4j
@RestController
@RequestMapping("/v1/notice")
public class NoticeController {
    @Autowired
    private INoticeService noticeService;

    @ApiOperation("保存通知方式")
    @PostMapping("/save")
    public Result saveNotice(@RequestBody BasicNotice basicNotice) {
        try {
            if(StringUtils.isEmpty(basicNotice.getId())){
                return Result.failure("通知id不能为空");
            }
            noticeService.saveNotice(basicNotice);
            return Result.success("保存成功");
        } catch (Exception e) {
            log.error("保存通知方式失败", e);
            return Result.failure(e.getMessage());
        }
    }

    @ApiOperation("查询通知方式列表")
    @GetMapping("/getNoticeList")
    public Result<List<BasicNotice>> getAllByOrgId() {
        try {
            List<BasicNotice> list = noticeService.getList();
            return Result.success(list);
        } catch (Exception e) {
            log.error("查询通知方式列表失败", e);
            return Result.failure( e.getMessage());
        }
    }
}
